/*--------------------------------------------------------------------------------------*\
**
** adv_ferry.cpp
**
** Heroes IV
** Copyright 2000, The 3DO Company
**
\*--------------------------------------------------------------------------------------*/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "adventure_events_look_trigger.h"

#include "adventure_map.h"
#include "adventure_map_window.h"
#include "army.h"
#include "game_time.h"

namespace 
{
	const int k_memory_event_buffer_size	= 0;
	const int k_event_lifespan				= 250;			//in mili-seconds
};

t_adventure_event_look_trigger::t_adventure_event_look_trigger ( ) 
: t_adventure_event_base ( k_look_trigger ) 
{ 
	m_trigger_dir	= k_direction_northeast;
}

t_adventure_event_look_trigger::t_adventure_event_look_trigger ( t_actor* adv_object , t_direction dir ) 
: t_adventure_event_base ( k_look_trigger ) 
{ 
	m_global_id		= adv_object->get_global_id();
	m_trigger_dir	= dir;
}

void t_adventure_event_look_trigger::execute_event( t_adventure_map* map , t_saved_game_header const & header ) 
{
	t_adventure_object * object = map->get_adventure_object_with_gid ( m_global_id );
	
	t_actor* actor = dynamic_cast<t_actor*>(object);
	
	if (actor == NULL) 
		return;
	
	actor->turn_to(m_trigger_dir);
	
	m_time_end = get_time() + k_event_lifespan;
}

void t_adventure_event_look_trigger::undo_event( t_adventure_map* map , t_saved_game_header const & header )
{

}

bool t_adventure_event_look_trigger::read( std::streambuf & buffer , int version )
{
	m_trigger_dir = get<t_direction> (buffer);

	return t_adventure_event_base::read( buffer , version );
}

bool t_adventure_event_look_trigger::write( std::streambuf & buffer )
{
	put<t_direction> (buffer, m_trigger_dir);

	return  t_adventure_event_base::write( buffer );
}
